{% extends "base.html" %}
{% block content %}
<h2>Appointment Management</h2>
<table>
<tr>
  <th>ID</th>
  <th>Patient</th>
  <th>Doctor</th>
  <th>Department</th>
  <th>Date</th>
  <th>Status</th>
  <th>Actions</th>
</tr>
{% for a in appointments %}
<tr>
  <td>{{ a.appointment_id }}</td>
  <td>{{ a.patient_name }}</td>
  <td>{{ a.staff_name }}</td>
  <td>{{ a.dept_name }}</td>
  <td>{{ a.appointment_date }}</td>
  <td>{{ a.status }}</td>
  <td>
    <form action="{{ url_for('appointment_cancel', appointment_id=a.appointment_id) }}" method="post" style="display:inline">
      <button>Cancel</button>
    </form>
  </td>
</tr>
{% endfor %}
</table>

<h3>New Appointment</h3>
<form action="{{ url_for('appointment_new') }}" method="post">
  Patient:
  <select name="patient_id">
    {% for p in patients %}
      <option value="{{ p.patient_id }}">{{ p.name }}</option>
    {% endfor %}
  </select>
  Doctor:
  <select name="staff_id">
    {% for s in staff %}
      <option value="{{ s.staff_id }}">{{ s.name }}</option>
    {% endfor %}
  </select>
  Date: <input name="appointment_date" type="date" required>
  <button type="submit">Submit</button>
</form>
{% endblock %}
